package com.zxt.controller;

import com.zxt.pojo.Emp;
import com.zxt.pojo.EmpQueryParam;
import com.zxt.pojo.PageResult;
import com.zxt.pojo.Result;
import com.zxt.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {
   //添加了默认值 如果不传值就用默认的
//    public Result  page(@RequestParam(defaultValue = "1")Integer page,
//                        @RequestParam(defaultValue = "10") Integer pageSize){
//              log.info("查询员工信息, page={}, pageSize={}", page, pageSize);
//
//
//              PageResult<Emp> pages = empService.page(page, pageSize);
//
//
//              return Result.success(pages);
//          }

    @Autowired
    private EmpService empService;
    @GetMapping
    public Result page(EmpQueryParam param) {
        log.info("查询员工信息,param{}", param);

        PageResult<Emp> pages = empService.page(param);
        return Result.success(pages);

    }
    @PostMapping
    public Result add(@RequestBody Emp emp){
        log.info("添加员工信息,emp{}", emp);
        empService.add(emp);

        return Result.success();
    }
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工信息,ids{}", Arrays.toString(ids.toArray()));
             empService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询员工信息,id{}", id);
        Emp emp = empService.getById(id);
        return Result.success(emp);
    }

    @PutMapping
    public Result update(@RequestBody Emp emp){
           log.info("修改员工信息为:{}",emp);
           empService.update(emp);


        return Result.success();
    }
}
















